package com.spring.spring_ioc_di.Controller;

import com.spring.spring_ioc_di.Config.StudentConfig;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/prop")
@RestController
public class PropertiesController {
    @Value("${my.key}")
    public String myKey;
    @PostConstruct
    public void readVal(){
        System.out.println(("从配置文件中读取配置信息:" + myKey));
    }
    @Value("${my.key2}")
    public Integer myKey2;
    @PostConstruct
    public void readVal2(){
        System.out.println(("从配置文件中读取配置信息:" + myKey2));
    }
    @Value("${my.key3}")
    public Boolean  myKey3;
    @PostConstruct
    public void readVal3(){
        System.out.println(("从配置文件中读取配置信息:" + myKey3));
    }
    @RequestMapping("/readVal2")
    public String readValR(){
        return "从配置文件中读取配置信息:"+myKey;
    }

    @Autowired
    public StudentConfig studentConfig;
    @RequestMapping("/readObject")
    public String readObject(){
        return studentConfig.toString();
    }
}
